﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using SalePartial.Utility;
using System.Collections;

public partial class controls_login_LoginProcess : System.Web.UI.UserControl
{

    Stack<RegStatusInfo> stkRegProcess = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack && stkRegProcess!=null)
        {
            foreach (RegStatusInfo info in stkRegProcess.ToArray<RegStatusInfo>())
            {
                _ChangeStatus(info.Process, info.Status);
            }
        }
    }

    public void FinshOneProcess(REG_PROCESS process, REG_STATUS status)
    {

        if (Session["REG_PROCESS"] == null)
        {
            Session["REG_PROCESS"] = new Stack<RegStatusInfo>();
        }
        stkRegProcess = (Stack<RegStatusInfo>)Session["REG_PROCESS"];

        RegStatusInfo info = new RegStatusInfo();
        info.Process = process;
        info.Status = status;

        if (!stkRegProcess.Contains(info))
        {
            //_ChangeStatus(process, status);

            stkRegProcess.Push(info);
        }
    }

    public void GoBackPreProcess()
    {
        stkRegProcess = (Stack<RegStatusInfo>)Session["REG_PROCESS"];
        if (stkRegProcess == null)
        {
            return;
        }
        if (stkRegProcess.Count > 0)
        {
            RegStatusInfo info = stkRegProcess.Pop();
            _ChangeStatus(info.Process, REG_STATUS.UNUSED);
        }

    }

    private void _ChangeStatus(REG_PROCESS process, REG_STATUS status)
    {
        Color color = Color.White;
        switch (status)
        {
            case REG_STATUS.SKIPED:
                color = Color.Gray;
                break;
            case REG_STATUS.UNUSED:
                color = Color.White;
                break;
            case REG_STATUS.USED:
                color = Color.Orange;
                break;
        }

        switch (process)
        {
            case REG_PROCESS.PERSON_INFO:
                lblPerson.BackColor = color;
                break;
            case REG_PROCESS.SUPPY_INFO:
                lblSupply.BackColor = color;
                break;
            case REG_PROCESS.PURCHASE_INFO:
                lblPurchase.BackColor = color;
                break;
            case REG_PROCESS.INFO_CONFIRM:
                lblConfirm.BackColor = color;
                break;
            case REG_PROCESS.REG_OK:
                lblRegOk.BackColor = color;
                break;
        }
    }

    public class RegStatusInfo
    {

        public REG_PROCESS Process{get;set;}

        public REG_STATUS Status { get; set; }
    }
}

